/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.odhixon.volarme.gui;

import com.odhixon.volarme.persistence.RegistroPerst;
import com.sun.lwuit.Component;
import com.sun.lwuit.Container;
import com.sun.lwuit.Label;
import com.sun.lwuit.List;
import com.sun.lwuit.layouts.BorderLayout;
import com.sun.lwuit.layouts.GridLayout;
import com.sun.lwuit.list.ListCellRenderer;
import java.util.Calendar;
import java.util.Date;

/**
 * RegistrosRender.
 * @author Ariel Aguirre <odhixon@gmail.com>
 */
public class RegistrosRender extends Container implements ListCellRenderer {

    private Label labelId;
    private Label labelFecha;
    private Label labelDuracion;
    private Label labelAterrizajes;
    private Label labelItinerario;
    private Label focus;

    public RegistrosRender() {
        setLayout(new BorderLayout());
        //Container container = new Container(new BoxLayout(BoxLayout.Y_AXIS));

        labelId = new Label();
        addComponent(BorderLayout.WEST, labelId);

        Container container = new Container(new GridLayout(2, 1));
        this.addComponent(BorderLayout.CENTER, container);

        Container containerSuperior = new Container(new GridLayout(1, 3));
        container.addComponent(containerSuperior);

        labelFecha = new Label();
        containerSuperior.addComponent(labelFecha);

        labelDuracion = new Label();
        containerSuperior.addComponent(labelDuracion);

        labelAterrizajes = new Label();
        containerSuperior.addComponent(labelAterrizajes);

        labelItinerario = new Label();
        container.addComponent(labelItinerario);

        focus = new Label();
    }

    public Component getListCellRendererComponent(List list, Object value, int index, boolean isSelected) {
        RegistroPerst registro = (RegistroPerst) value;
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date(registro.getFecha()));
        labelId.setText(Integer.toString(registro.getId()));
        labelFecha.setText(Integer.toString(calendar.get(Calendar.DAY_OF_MONTH)) + "/" + Integer.toString(calendar.get(Calendar.MONTH) + 1) + "/" + Integer.toString(calendar.get(Calendar.YEAR)));
        labelDuracion.setText(registro.getDuracion() + " hrs");
        labelAterrizajes.setText(Integer.toString(registro.getAterrizajes()) + " aterrizajes");
        labelItinerario.setText(registro.getItinerario());

        if (isSelected) {
            labelId.setUIID("LABEL_FOCO");
            labelFecha.setUIID("LABEL_FOCO");
            labelDuracion.setUIID("LABEL_FOCO");
            labelAterrizajes.setUIID("LABEL_FOCO");
            labelItinerario.setUIID("LABEL_FOCO");
        } else {
            labelId.setUIID("LABEL_ID");
            labelFecha.setUIID("LABEL_FECHA");
            labelDuracion.setUIID("LABEL_DURACION");
            labelAterrizajes.setUIID("LABEL_ATERRIZAJES");
            labelItinerario.setUIID("LABEL_ITINERARIO");
        }

        return this;
    }

    public Component getListFocusComponent(List list) {
        return focus;
    }
}
